<template lang="html">
    <div class="finance">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-tickets"></i> 财务管理</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div style="padding-bottom:50px;text-indent:20px;">
                <div style="font-size:20px">
                    销售总金额：<span style="font-size:50px;">{{sumMoney}}</span>元
                    <span style="padding-left:60px"></span>当前页销售金额：<span style="font-size:50px;">{{pageSumMoney}}</span>元
                </div>
            </div>
            <el-form :inline="true" class="demo-form-inline" >
                <el-form-item label="订单号" label-width="80px">
                    <el-input v-model="order_code" placeholder="请输入订单号" style="width:250px"></el-input>
                </el-form-item>
                <el-form-item label="用户昵称" label-width="80px">
                    <el-input v-model="nickName" placeholder="请输入用户昵称" style="width:250px"></el-input>
                </el-form-item>
                <div>
                    <el-form-item label="开始日期" label-width="80px">
                        <el-date-picker value-format="yyyy-MM-dd" v-model="startDate" type="date" class="handle-date"
                                        placeholder="选择日期" style="width:250px;"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="结束日期" label-width="80px">
                        <el-date-picker value-format="yyyy-MM-dd" v-model="endDate" type="date" class="handle-date"
                                        placeholder="选择日期" style="width:250px;"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="来源">
                        <el-select v-model="source" placeholder="请选择来源分类">
                            <el-option label="商品" value="1"></el-option>
                            <el-option label="拼团项目" value="3"></el-option>
                            <el-option label="普通项目" value="2"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="search">查询</el-button>
                        <el-button type="info" @click="exprot">导出</el-button>
                    </el-form-item>
                </div>
                
               <!-- <el-form-item>
                    <el-button type="primary" @click="reset">重置</el-button>
                </el-form-item>-->
            </el-form>
            <el-table :data="tableData" bfinance style="width: 100%" ref="multipleTable">
                <el-table-column prop="order_code" label="订单号" width="240"></el-table-column>
                <el-table-column prop="name" label="产品名称" ></el-table-column>
                <el-table-column prop="nick_name" label="下单用户昵称" width="180" align="center"></el-table-column>
                <el-table-column prop="discount_money" label="优惠券抵扣" width="150" align="center"></el-table-column>
                <el-table-column prop="pay_money" label="流水金额" width="150" align="center"></el-table-column>
                <el-table-column prop="payText" label="支付方式" width="150" align="center"></el-table-column>
                <el-table-column prop="create_time" label="下单时间" width="180" align="center"></el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination @current-change="handleCurrentChange" :page-size="pageSize"  layout="prev, pager, next" :total="totalPages">
                </el-pagination>
            </div>
        </div>
    </div>

  </div>
</div>
</template>

<script>
    export default {
        name: "finance",
        data() {
            return {
                pageSumMoney:0,
                sumMoney:0,
                pageIndex: 1,//当前页码
                pageSize: 10,//每页12条
                totalPages: 1,//默认的总条数
                tableData: [],//表格数据
                delVisible: false, //删除确认提示，默认隐藏
                order_code: '',
                source: '1',
                nickName: '',//订单名称
                financeCode: '',//订单编号
                startDate: '',
                endDate: '',//开始日期
                value: ''
            }
        },
        mounted() {
            this.getFinanceData();
        },
        methods: {
            //获取data数据
            getFinanceData() {
                var _this =this;
                const querystring = require('querystring');

                const param = {
                    id: this.order_code,
                    nickName: this.nickName,
                    source: this.source,
                    pageIndex: this.pageIndex,
                    pageSize: this.pageSize,
                    startDate: this.startDate,
                    endDate: this.endDate,
                }

                this.$axios
                    .post('/manage/finance/list', querystring.stringify(param))
                    .then(response => {
                        // console.log(response);
                        if (response.data.code == 200) {
                            _this.totalPages = response.data.data.totalElements;
                            let data = response.data.data.currData;
                            let obj = data;
                            obj.forEach(element => {
                                if(element.pay_type==1){
                                    element.payText ="微信支付";
                                }else{
                                    element.payText ="到店支付";
                                }
                            });
                            _this.tableData = obj;//赋值 table 列表数据
                            //更新金额  总金额， 当前金额
                            _this.pageSumMoney = response.data.data.data.pageSumMoney;
                            _this.sumMoney = response.data.data.data.sumMoney;


                        } else {
                            console.log(response.data.msg)
                        }
                    })
                    .catch(error => {
                        console.log(error);
                    });
            },
            // 分页导航
            handleCurrentChange(val) {
                this.pageIndex = val
                this.getFinanceData()
                // this.cur_page = val;
                //     this.getData();
            },
            //查询
            search() {
                this.getFinanceData();
            },
            //导出
            exprot(){
                if(this.startDate!="" &&this.endDate==""||this.startDate=="" &&this.endDate!=""){
                    this.$notify({
                        title: '警告',
                        message: '请选择开始日期与结束日期',
                        type: 'warning'
                    });
                }else{
                    var str ="";
                    if(this.order_code!=""){
                        str +='&id='+this.order_code;
                    }
                    if(this.nickName!=""){
                        str +='&nickName='+this.nickName;
                    }
                    if(this.startDate!=""){
                        str +='&startDate='+this.startDate;
                    }
                    if(this.endDate!=""){
                        str +='&endDate='+this.endDate;
                    }
                    if(str!=""){
                        str ="?"+str.slice(1);
                    }
                    
                    //console.log(str);
                    window.open("http://api.xfkka.com/manage/finance/export"+str);  
                }
                
                
            }
        }
    }
</script>

<style lang="stylus" scoped>
     
</style>
